﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace EBA.Framework
{

    /// <summary>
    /// 插件包含的文件列表
    /// </summary>
    [ConfigurationCollection(typeof(FileConfigurationElement), AddItemName = "add", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class FileConfigurationElementCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// 新建一个插件文件列表配置节点
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new FileConfigurationElement();
        }

        /// <summary>
        /// 获取插件文件配置节点的标识
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((FileConfigurationElement)element).Name;
        }

        /// <summary>
        /// 文件列表
        /// </summary>
        public IEnumerable<FileConfigurationElement> AsEnumerable
        {
            get
            {
                for (var i = 0; i < this.Count; i++)
                {
                    yield return (FileConfigurationElement)BaseGet(i);
                }
            }
        }

        /// <summary>
        /// 新增一个文件配置节点
        /// </summary>
        /// <param name="fileName"></param>
        public void Add(string fileName)
        {
            BaseAdd(new FileConfigurationElement { Name = fileName });
        }
    }
}
